SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
SET(WPSHELPER_SOURCE main.cpp helper.cpp brightness.cpp restreminder.cpp helperstyle.cpp khelpermainwindow.cpp brightness_clock.cpp)

if(UNIX)
  set(WPSHELPER_SOURCE ${WPSHELPER_SOURCE} maintainworktimestampsthread.cpp keylogger.cpp)
elseif(WIN32)
endif(UNIX)

SET(WPSHELPER_HEADERS helper.h restreminder.h helperstyle.h khelpermainwindow.h brightness_clock.h)
SET(WPSHELPER_RESOURCES systray.qrc)

# translations
set(languages fr_FR zh_CN en_US)
set(lanauges_ts_files)

foreach(language ${languages})
  set(ts_file "${CMAKE_CURRENT_SOURCE_DIR}/../i18n/wpshelper_${language}.ts")
  set(languages_ts_files ${languages_ts_files} ${ts_file})
  set_source_files_properties(${ts_file} PROPERTIES OUTPUT_LOCATION "${CMake_BINARY_DIR}${CMAKE_DATA_DIR}/i18n")
endforeach(language)
if(languages_ts_files)
  qt4_create_translation(qm_files ${WPSHELPER_SOURCE} ${languages_ts_files})
endif(languages_ts_files)

# macro(translate_ts_files infiles outpath)
#   foreach(file ${infiles})
# 	get_filename_component(filename ${file} NAME_WE)
# 	set(outfile ${outpath}/${filename}.qm)
# 	message("${file}====${outpath}====${outfile}====${QT_LRELEASE_EXECUTABLE}")

# 	add_custom_command(
# 	  OUTPUT ${outfile}
# 	  COMMAND ${QT_LRELEASE_EXECUTABLE} ARGS ${file} -qm ${outfile}
# 	  DEPENDS ${file}
# 	  COMMENT "Compilation qt translations files"
# 	  )
# 	add_custom_target(qm_files ALL DEPENDS ${outfile})
#   endforeach()
# endmacro(translate_ts_files)

# translate_ts_files("/home/sai/Workspace/wpshelper/i18n/wpshelper_zh_CN.ts" "${PROJECT_BINARY_DIR}i18n")

# qt4_wrap_cpp
QT4_WRAP_CPP(WPSHELPER_HEADERS_MOC ${WPSHELPER_HEADERS})
QT4_ADD_RESOURCES(WPSHELPER_RESOURCES_MOC ${WPSHELPER_RESOURCES})
INCLUDE(${QT_USE_FILE})

# compile
ADD_DEFINITIONS(${QT_DEFINITIONS})
ADD_EXECUTABLE(wpshelper ${WPSHELPER_SOURCE} ${WPSHELPER_HEADERS_MOC} ${WPSHELPER_RESOURCES_MOC} ${qm_files})

# linking
SET(WPSHELPER_NEEDED_LIBRARIES ${QT_LIBRARIES})
if(UNIX)
  set(WPSHELPER_NEEDED_LIBRARIES ${WPSHELPER_NEEDED_LIBRARIES} xcb xcb-util xcb-randr m X11 Xtst)
elseif(WIN32)
  set(WPSHELPER_NEEDED_LIBRARIES ${WPSHELPER_NEEDED_LIBRARIES} ${QT_LIBRARY_DIR}/qtmaind.lib)
endif(UNIX)

INSTALL_TARGETS(/bin wpshelper)

TARGET_LINK_LIBRARIES(wpshelper ${WPSHELPER_NEEDED_LIBRARIES})

